package models

import (
	"shop-hub/shoprpc/shoprpc"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Account   string `gorm:"type:char(11);not null;"`
	Password  string `gorm:"type:char(32);not null;"`
	NickName  string `gorm:"type:varchar(30);not null;"`
	HeadImage string `gorm:"type:varchar(500);not null;"`
}

type Good struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(30);not null;"`
	Price  float64 `gorm:"type:decimal(10,2);not null;"`
	Image  string  `gorm:"type:varchar(500);not null;"`
	Num    int     `gorm:"type:int(11);not null;"`
	UserId int     `gorm:"type:int(11);not null;"`
}

func (g *Good) GoogList(db *gorm.DB) ([]*shoprpc.GoodList, error) {
	var lists []*shoprpc.GoodList

	err2 := db.Debug().Model(&Good{}).
		Select(" goods.*, goods.id AS good_id,goods.title, goods.price,goods.image, goods.num, goods.user_id ").
		Find(&lists).Error

	return lists, err2
}
